package com.athu.study.controller;

import com.athu.study.service.ChatAssiatant;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.tika.metadata.FileSystem;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.file.Path;
import java.nio.file.Paths;

@RestController
@Slf4j
public class RAGController {
    @Resource
    private InMemoryEmbeddingStore<TextSegment> embeddingStore;
    @Resource
    private ChatAssiatant chatAssiatant;
    @GetMapping(value = "/rag/add")
    public String testAdd() {
        Path filePath = Paths.get("D:/资料/共享资料/4、（不用下载）其他资料/bs.docx");
        Document document = FileSystemDocumentLoader.
                loadDocument(filePath);
        EmbeddingStoreIngestor.ingest(document,embeddingStore);
        String chat = chatAssiatant.chat("案例2提取码是多少");
        System.out.println(chat);
        return chat;
    }
}
